/**
 * 自定义接口
 * */


//博客列表
function getBlogList(){
    $.ajax({
        type: apis.blogList.method,
        url: apis.blogList.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key;
            for (var i = 0; i < d.length; i ++) {
                key = d[i].fkey;
                if (d[i].ftype == 3) {
                    $('#' + key).attr('src', d[i].fval);
                } else if (d[i].ftype == 4) {
                    partList({k: key, v: d[i].fval});
                } else {
                    $('#' + key).html(d[i].fval);
                }
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//数据4列表
function partList(e){
    var d = e.v, key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<div class="row mt_30" data-animation>';
        h += '<div class="col-xl-5 col-lg-5 col-md-6">';
        h += '<a href="blog_details.html" data-cursor=\'<i class="fx-icon-long-next-arrow"></i>\' class="blog_list_img d-block">';
        h += '<div data-animation="img-blur">';
        //h += '<img src="images/blog_list_img_1.jpg" alt="blog" class="img-fluid w-100"/>';
        h += '<img src="' + d[i][0] + '" alt="blog" class="img-fluid w-100"/>';
        h += '</div>';
        h += '</a>';
        h += '</div>';
        h += '<div class="col-xl-5 col-lg-7 col-md-6">';
        h += '<div class="blog_list_text">';
        h += '<span>Marketing</span>';
        h += '<ul>';
        h += '<li>';
        //h += '<p><i class="far fa-calendar-check"></i> September 25, 2022</p>';
        h += '<p><i class="far fa-calendar-check"></i>' + d[i][1] + '</p>';
        //h += '<p><i class="far fa-comment-dots"></i> No Comments</p>';
        h += '<p><i class="far fa-comment-dots"></i>' + d[i][2] + '</p>';
        h += '</li>';
        h += '</ul>';
        //h += '<a href="blog_details.html">Creative advertising our life became noise.</a>';
        h += '<a href="blog_details.html">' + d[i][3] + '</a>';
        h += '</div>';
        h += '</div>';
        h += '</div>';
    }
    $('#' + key).html(h);
}


//博客网格
function getBlogGrid(){
    $.ajax({
        type: apis.blogGrid.method,
        url: apis.blogGrid.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key;
            for (var i = 0; i < d.length; i ++) {
                key = d[i].fkey;
                if (d[i].ftype == 3) {
                    $('#' + key).attr('src', d[i].fval);
                } else if (d[i].ftype == 4) {
                    gridList({k: key, v: d[i].fval});
                } else {
                    $('#' + key).html(d[i].fval);
                }
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//网格列表
function gridList(e){
    var d = e.v, key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<div class="col-lg-4 col-md-6">';
        h += '<div class="single_blog first_blog">';
        h += '<div class="single_blog_text">'
            + '<ul class="d-flex flex-wrap">'
            //+ '<li>User Experience</li>'
            + '<li>' + d[i][0] + '</li>'
            //+ '<li>September 10, 2023</li>'
            + '<li>' + d[i][1] + '</li>'
            //+ '<a class="title" href="blog_details.html">Creative advertising our life became noise.</a>'
            + '<a class="title" href="blog_details.html">' + d[i][2] + '</a>'
            + '</ul>'
            + '</div>'
            + '<a class="single_blog_img">'
            + '<a href="blog_details.html" data-cursor=\'<i class="fx-icon-long-next-arrow"></i>\' class="img d-block">'
            + '<div data-animation="img-blur" data-delay="0">'
            //+ '<img src="images/blog_1.jpg" alt="blog" class="img-fluid w-100"/>'
            + '<img src="' + d[i][3] + '" alt="blog" class="img-fluid w-100"/>'
            + '</div>'
            + '</a>'
            + '';
        h += '</div>';
        h += '</div>';
        h += '</div>';
    }
    $('#' + key).html(h);
}


//博客详情
function getBlogDetail(){
    $.ajax({
        type: apis.blogDetail.method,
        url: apis.blogDetail.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key, id;
            for (var i = 0; i < d.length; i ++) {
                id = d[i].id;
                key = d[i].fkey;
                if (d[i].ftype == 3) {
                    $('#' + key).attr('src', d[i].fval);
                } else if (d[i].ftype == 4) {
                    if (id == 196) {
                        detailPart1({k: key, v: d[i].fval});
                    }
                    if (id == 204) {
                        detailPart2({k: key, v: d[i].fval});
                    }
                    if (id == 206) {
                        detailPart3({k: key, v: d[i].fval});
                    }
                    if (id == 208) {
                        detailPart4({k: key, v: d[i].fval});
                    }
                } else {
                    $('#' + key).html(d[i].fval);
                }
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//详情1
function detailPart1(e){
    var d = e.v, key = e.k;
    var h = '', i;
    //for (i = 0; i < d.length; i ++) {
    //}
    h += '<li>'
        + '<div class="img">'
        //+ '<img src="images/details_bloger.png" alt="bloger" class="img-fluid w-100"/>'+
        + '<img src="' + d[0][0] + '" alt="bloger" class="img-fluid w-100"/>'+
        + '</div>'
        + '</li>';
    h += '<li>'
        //+ '<h4>Written by</h4>'
        + '<h4>' + d[0][1] + '</h4>'
        //+ '<p>Tomas Markt</p>'
        + '<p>' + d[0][2] + '</p>'
        + '</li>';
    h += '<li>'
        //+ '<h4>Viewed</h4>'
        + '<h4>' + d[0][3] + '</h4>'
        //+ '<p>3 min read</p>'
        + '<p>' + d[0][4] + '</p>'
        + '</li>';
    h += '';
    $('#' + key).html(h);
}


//详情2
function detailPart2(e){
    var d = e.v, key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<li>'
            + '<div class="img">'
            + '<img src="' + d[i][0] + '" alt="post" class="img-fluid w-100"/>'+
            + '</div>'
            + '</div>'
            + '<div class="text">'
            + '<a href="blog_details.html">' + d[i][1] + '</a>'
            + '<p>' + d[i][2] + '</p>'
            + '</div>'
            + '</li>';
        h += '';
    }
    $('#' + key).html(h);
}


//详情3
function detailPart3(e){
    var d = e.v[0], key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<p>' + d[i] + '</p>';
    }
    $('#' + key).html(h);
}


//详情4
function detailPart4(e){
    var d = e.v[0], key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<li><a href="#">' + d[i] + '</a></li>';
    }
    $('#' + key).html(h);
}